package leetcode_301_400;

import java.util.HashSet;
import java.util.Set;

public class LeeCode_349 {
    public static void main(String[] args) {

    }
    private static int[] intersection(int[] nums1, int[] nums2) {
        Set<Integer> n1 = new HashSet<>();
        for (int i : nums1) {
            n1.add(i);
        }
        Set<Integer> res = new HashSet<>();
        for (int i : nums2) {
            if (n1.contains(i)){
                res.add(i);
            }
        }
        int[] ans = new int[res.size()];
        int index = 0;
        for (int re : res) {
            ans[index] = re;
            index++;
        }
        return ans;
    }
}
